/*
 * Created on 29.08.2007
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package at.fhv.dcs.aw.j2me.lcdui.game;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class LabyrinthMIDlet extends MIDlet implements CommandListener {

    Display m_display;
    Labyrinth m_labyrinth;
    Alert m_YouDieAlert;
    
    public LabyrinthMIDlet() {
        // TODO Auto-generated constructor stub
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // TODO Auto-generated method stub
    }

    protected void pauseApp() {
        // TODO Auto-generated method stub
    }

    protected void startApp() throws MIDletStateChangeException {
        if (m_display == null) {
            m_display = Display.getDisplay(this);
            
            m_labyrinth = new Labyrinth(false, this);
            
            new Thread(m_labyrinth).start();
            
            m_display.setCurrent(m_labyrinth);
        }
    }

    public void showYouDie() {        
        m_YouDieAlert = new Alert("You die...");
        m_YouDieAlert.setTimeout(Alert.FOREVER);
        m_display.setCurrent(m_YouDieAlert);
        
        m_YouDieAlert.setCommandListener(this);
    }

    public void commandAction(Command cmd, Displayable d) {
        if (d == m_YouDieAlert && cmd == Alert.DISMISS_COMMAND) {            
            try {
                destroyApp(true);
            } catch (MIDletStateChangeException e) {
                e.printStackTrace();
            }
            notifyDestroyed();
        }        
    }
}
